<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
$ordering = ($this->lists['order'] == 'ordering');

?>
<?php  JHTML::_('behavior.tooltip');  ?>
<?php
	JToolBarHelper::title( JText::_( '&nbsp;&nbsp;&nbsp;'.JText::_( 'title_PARTNERI' ) ), 'partneri' );
	// JToolBarHelper::unarchiveList('unarchive','Odarchivovat');
  // JToolBarHelper::archiveList();
  JToolBarHelper::addNew();
	JToolBarHelper::editListX();
  JToolBarHelper::deleteList();	
//	JToolBarHelper::preferences('com_jzmluvy', '500');
//	JToolBarHelper::help( 'screen.users' );
  $params	= &JComponentHelper::getParams('com_jzmluvy');
 
      // viacej odberatelov ako je nastavene 
      if($this->pocet(0) > $this->nastavenie->partner_pocet_obj)
      {    
        $error = JText::_( 'INFO_OBJEDNAVATEL_ERROR'); 
        JError::raiseWarning('SOME_ERROR_CODE', $error );
      }
      
      // nie je zadefinovany ziaden odberatel
      if(!$this->pocet(0))
      {    
        $error = JText::_( 'INFO_OBJEDNAVATEL_NIC'); 
        JError::raiseWarning('SOME_ERROR_CODE', $error );
      }      
      // ak je zadefinovanych menej odveratelov ako je nastavene
      elseif($this->pocet(0) < $this->nastavenie->partner_pocet_obj)
      {    
        $error  = JText::_( 'INFO_OBJEDNAVATEL_MENEJ' ).$this->nastavenie->partner_pocet_obj;
        $error .= JText::_( 'INFO_OBJEDNAVATEL_MENEJ2' ).$this->pocet(0);
        $error .= JText::_( 'INFO_OBJEDNAVATEL_MENEJ3' ).($this->nastavenie->partner_pocet_obj-$this->pocet(0)).".";
        JError::raiseNotice('SOME_ERROR_CODE', $error );
      }
      
/*
echo "<pre>";
print_r(JFactory::getUser());
echo "</pre>";
*/

?>
<form action="index.php?option=com_jzmluvy" method="post" name="adminForm">
  <table>
    <tr> 
			<td width="100%">
				<?php echo JText::_( 'FILTER' ); ?>:
				<input type="text" name="search" id="search" value="<?php echo htmlspecialchars($this->lists['search']);?>" class="text_area" onchange="document.adminForm.submit();" />
				<button onclick="this.form.submit();"><?php echo JText::_( 'POUZI' ); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.getElementById('filter_type').value='0';this.form.getElementById('filter_logged').value='0';this.form.submit();"><?php echo JText::_( 'ZRUSIT' ); ?></button>
			</td>
      <td nowrap="nowrap">
        <?php // echo $this->lists['anotace'];?>
        <?php //**** echo $this->lists['archiv'];?>
        <?php //*** echo $this->lists['kategorie'];?></td>
    </tr>
  </table>
  <table class="adminlist" cellpadding="1">
    <thead>
      <tr>
        <th width="2%" class="title">
          <?php echo JText::_( 'NUM' ); ?>
        </th>
        <th width="3%" class="title">
          <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
        </th>
        <th width="2%" class="title" nowrap="nowrap">
          <?php echo JHTML::_('grid.sort',  JText::_( 'FAVORIT' ), 'reserverd', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
        <th  class="title"> 
          <?php echo JHTML::_('grid.sort', JText::_( 'pa_PARTNER' ) , 'title', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
      
        <th width="10%" class="title" >
          <?php echo JHTML::_('grid.sort', JText::_( 'pa_ICO' ), 'ico', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
        <th width="20%" class="title" >
          <?php echo JHTML::_('grid.sort',   JText::_( 'pa_ADRESA' ), 'psc', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
        <th width="2%" class="title" nowrap="nowrap">
          <?php echo JHTML::_('grid.sort',  JText::_( 'pa_LOGO' ) , 'logo', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
        <th width="2%" class="title" nowrap="nowrap">
          <?php echo JHTML::_('grid.sort',  JText::_( 'POVOL' ), 'published', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th>
         <?php if($this->params->get('debug')) : ?>
        <th width="1%" class="title" nowrap="nowrap">
          <?php echo JHTML::_('grid.sort',   'ID', 'id', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
        </th><?php endif; ?>
      </tr>
    </thead>
    <tfoot>
      <tr> 
        <td colspan="8">
          <?php echo $this->pagination->getListFooter(); ?></td>
      </tr>
    </tfoot>
   
<?php
			for ($e = 0; $e <= 1; $e++) {
      $k = 0;
      ?> <tbody> <?php
      for ($i=0, $n=count( $this->items ); $i < $n; $i++)
			{
        $ordering   = ($this->lists['order'] == 'ordering');
        $row 	=& $this->items[$i];

        $link 	= 'index.php?option=com_jzmluvy&amp;view=upravapartner&amp;hidemainmenu=1&amp;task=edit&amp;id[]='. $row->id. '';
				$published 	= JHTML::_('grid.published', $row, $i );

				// casto pouzivany dodavatelia / favoriti
  			$img_sub  = $row->reserverd ? 'bookmark_f2.png' : 'bookmark.png';
				$task     = $row->reserverd ? 'unfavorit' : 'favorit';
        $alt      = $row->reserverd ? JText::_( 'PA_FAVITIT_E' ) : JText::_( 'PA_FAVITIT_E' );
        $action   = $row->reserverd ? JText::_( 'PA_UNFAVORIT_I' ) : JText::_( 'PA_FAVORIT_I' );
        $favorit = '<a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''.$task .'\')" title="'. $action .'"><img src="images/'. $img_sub .'" border="0" alt="'. $alt .'" width="16" height="16" /></a>';
        
        // prideli ikonu podla toho ci logo je lebo nie        
        $logo_icon 	= $row->logo ? 'themes_f2.png' : 'blank.png';
        $logo = '<img src="images/'. $logo_icon .'" border="0" title="Partner s logom" alt="Logo" width="16" height="16" />';

        // prideli ikonu ak je to objednavatel        
        $dod_icon 	= $row->typ ? 'blank.png' : 'frontpage.png';
        $dodavatel = '&nbsp;&nbsp;&nbsp;<img src="images/'. $dod_icon .'" border="0" alt="Ikona" title="Odberateľ" width="16" height="16" />';
                
        // zobraz meno ak nie je zobraz firmu
        If ($row->title == '' ) { $partner = $row->meno; } else { $partner = $row->title; }
        
        // kontola povinnych udajov
        if((empty($partner)) || (empty($row->ulica)) || (empty($row->mesto)) || (empty($row->psc)) || (empty($row->stat)))
        {
        $chyba = jzmluvyHelper::obrazok('chyba-16.png','',JText::_( 'pa_chybny' ));
        }
        else 
        {
        $chyba = "";
        } 
        ?>
     
         			                             
      <?php if ($row->typ == $e) { ?>
      <tr class="row<?php echo $k ?>">    <td>
          <?php echo $i+1+$this->pagination->limitstart;?>        </td>    <td>
          <?php echo JHTML::_('grid.id', $i, $row->id ); ?>        </td>
                        <td  align="center">
          <?php echo $favorit;?>        </td>
          
              <td> 
          <a href="<?php echo $link ?>">
            <?php echo $chyba.$partner.$dodavatel; ?>
             </a>

             <?php if($row->typ)  :?>
             <br />
             <span style="padding-left: 20px;">(Zmluvy: <?php echo $this->partner($row->id,2) ?>; </span>
             <span>Faktúry: <?php echo $this->partner($row->id,1) ?>; </span>
             <span>Objednávy: <?php echo $this->partner($row->id,3) ?>)</span>
             <?php endif; ?>
             
             </td>
             


              <td>
          <?php echo $row->ico; ?>       </td> <td>
          <?php echo $row->ulica; ?>,
          <?php echo substr($row->psc, 0, 3)," ",substr($row->psc, 3, 2)." "; ?>
          <?php echo $row->mesto; ?>  </td> 
        <td align="center">
          <?php echo $logo;?>        </td> <td align="center">
          <?php echo $published;?>        </td>
       <?php if($this->params->get('debug')) : ?>
          <td><?php echo $row->id; ?></td>
        <?php endif; ?>
      </tr>
      <?php	$k = 1 - $k; 	}	}?>    		                     
    
    </tbody>
         
     <?php } ?>
          
     
    
  </table> 
  <input type="hidden" name="option" value="com_jzmluvy" /> 
  <input type="hidden" name="view" value="partner" /> 
  <input type="hidden" name="controller" value="upravapartner" /> 
  <input type="hidden" name="boxchecked" value="0" /> 
  <input type="hidden" name="task" value="" /> 
  <input type="hidden" name="redirect" value="<?php //echo $redirect; ?>" /> 
  <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" /> 
  <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
  <?php echo JHTML::_( 'form.token' ); ?>
</form>